package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.jingjiu.homeservicesapi.domain.OrderItem;
import com.jingjiu.homeservicesbiz.service.IOrderItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单明细：支持一个订单多商品/食品Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@Controller
@RequestMapping("/system/item")
public class OrderItemController extends BaseController
{

    @Autowired
    private IOrderItemService orderItemService;


    /**
     * 查询订单明细：支持一个订单多商品/食品列表
     */
    @RequiresPermissions("system:item:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderItem orderItem)
    {
        startPage();
        List<OrderItem> list = orderItemService.selectOrderItemList(orderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单明细：支持一个订单多商品/食品列表
     */
    @RequiresPermissions("system:item:export")
    @Log(title = "订单明细：支持一个订单多商品/食品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestBody OrderItem orderItem)
    {
        List<OrderItem> list = orderItemService.selectOrderItemList(orderItem);
        ExcelUtil<OrderItem> util = new ExcelUtil<OrderItem>(OrderItem.class);
        return util.exportExcel(list, "订单明细：支持一个订单多商品/食品数据");
    }



    /**
     * 新增保存订单明细：支持一个订单多商品/食品
     */
    @RequiresPermissions("system:item:add")
    @Log(title = "订单明细：支持一个订单多商品/食品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody OrderItem orderItem)
    {
        return toAjax(orderItemService.insertOrderItem(orderItem));
    }

    /**
     * 修改订单明细：支持一个订单多商品/食品
     */
    @RequiresPermissions("system:item:edit")
    @GetMapping("/get/{id}")
    public OrderItem getById(@PathVariable("id") Long id)
    {
        OrderItem orderItem = orderItemService.selectOrderItemById(id);
        return orderItem;
    }

    /**
     * 修改保存订单明细：支持一个订单多商品/食品
     */
    @RequiresPermissions("system:item:edit")
    @Log(title = "订单明细：支持一个订单多商品/食品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody OrderItem orderItem)
    {
        return toAjax(orderItemService.updateOrderItem(orderItem));
    }

    /**
     * 删除订单明细：支持一个订单多商品/食品
     */
    @RequiresPermissions("system:item:remove")
    @Log(title = "订单明细：支持一个订单多商品/食品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderItemService.deleteOrderItemByIds(ids));
    }
}
